package util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * User: Алексей
 * Date: 13.11.12
 * Time: 19:45
 */
public class SortedList<T> extends ArrayList<T> {

    private Comparator<? super T> comparator;

    public SortedList(Comparator<? super T> comparator) {
        this.comparator = comparator;
    }

    @Override
    public boolean add(T paramT) {
        int insertionPoint = Collections.binarySearch(this, paramT, comparator);
        super.add((insertionPoint > -1) ? insertionPoint : (-insertionPoint) - 1, paramT);
        return true;
    }

}
